<template>
	<view>
		<uni-nav-bar left-icon="back" left-text="返回" fixed="true" statusBar="true"  @clickLeft="leftAction"  title="基站使用情况"
			></uni-nav-bar>
		<uni-list>
			<template v-for="(item,index) in listData">
				<uni-list-item :title="'基站名:'+item.bsName" :note="'当前使用者:'+item.user"  clickable :rightText="currentUser==item.user?'退出':''"
					@click="currentUser==item.user?onClickItem(index):null" />
			</template>			
		</uni-list>
	</view>
</template>

<script>
	import uniNavBar from '@/uni_modules/uni-nav-bar/components/uni-nav-bar/uni-nav-bar.vue'
	
	export default {
		data() {
			var value = ''
			try {
				value = uni.getStorageSync('login_user');
			}catch{
			}
			return {
				listData:[],
				currentUser:value,
			};
			
		},
		components: {
			uniNavBar
		},
		onLoad() {
			this.fetchData();
		},
		methods: {
			leftAction() {
				uni.navigateBack({
					delta: 1
				});
			},
			rightAction() {
				
			},
			onClickItem(index){
				console.log(index)
				uni.showModal({
					title:"是否要退出使用",
					showCancel:true,
					success:res => {
						if (res.confirm) {
							const model = this.listData[index]
							this.$http.put('/netty/info/',{id:model.id,isUse:0}).then(res=>{
								this.fetchData()
								uni.showModal({
									content: '退出成功',
									showCancel: false
								})
							}).catch(error=>{
								uni.showModal({
									content: '出错了，请稍后再试',
									showCancel: false
								})
							})
						}
						
					}
				})
				this.fetchData()
			},
			fetchData(){
				this.$http.get('/netty/info/list?isUse=1&pageSize=1000&pageNum=1').then(res =>{
					const list = res.data.rows;
					this.listData = list;
					
				}).catch(err =>{
					uni.showModal({
						content: '出错了，请稍后再试',
						showCancel: false
					})
				})
			},
		}
	}
</script>

<style lang="scss">
	@import '@/common/uni-nvue.scss';

</style>
